﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iData;
using System.Data.SqlClient;
using iComm;

namespace Teein.LiNing.DAL
{
    public class DALBase : CommClass
    {
        public string ConnStr = System.Configuration.ConfigurationManager.ConnectionStrings["sql_con"].ToString();
        public iData.DataSqlClient myData;

        public DALBase()
        {
            myData = new DataSqlClient();
        }

        /// <summary>
        /// 由于WHERE条件不确定性 可以用LIST集合代替数组
        /// </summary>
        /// <param name="listP">SqlParameter 所有的LIST集合</param>
        /// <returns></returns>
        public SqlParameter[] getSqlParameters(List<SqlParameter> listP)
        {
            if (listP == null || listP.Count == 0)
                return null;

            SqlParameter[] ps = new SqlParameter[listP.Count];

            for (int i = 0; i < listP.Count; i++)
            {
                ps[i] = listP[i];
            }
            return ps;
        }

        /// <summary>
        /// 对数据进行缓存(缓存1个小时) 
        /// </summary>
        /// <param name="table">需要缓存的对象</param>
        /// <param name="keyName">缓存的名称</param>
        /// <returns></returns>
        internal bool SetCacheTable(object table, string keyName)
        {
            try
            {
                System.Web.HttpContext.Current.Cache.Insert(keyName, table, null, DateTime.Now.AddMinutes(60), System.Web.Caching.Cache.NoSlidingExpiration);
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 获取缓存数据(缓存1个小时) 
        /// </summary>
        /// <param name="keyName">缓存的名称</param>
        /// <returns></returns>
        internal object GetCacheTable(string keyName)
        {
            try
            {
                return System.Web.HttpContext.Current.Cache[keyName];
            }
            catch
            {
                return null;
            }
        }
    }
}
